/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package eu.fastl.dragster.log.exec;

import java.io.File;
import java.util.Map;
import java.util.TreeSet;

import eu.fastl.dragster.log.service.LogAnalyserService;
import eu.fastl.dragster.log.service.LogParserResult;
import eu.fastl.dragster.log.service.LogParserService;
import eu.fastl.dragster.log.service.impl.LogAnalyserServiceSimpleImpl;
import eu.fastl.dragster.log.service.impl.LogParserServiceSimpleImpl;

/**
 * Command Line Tool for Basic Performance Log Analysis
 * @author Robert Benak
 *
 */
public class LogParserExec {

	public static void main(String args[]) {

		if (args.length < 1) {
			System.out.println("Please specify the log data source file!");
			return;
		}
		String filename = args[0];
		File file = new File(filename);

		LogParserService logParserService = new LogParserServiceSimpleImpl();
		LogParserResult parserResult = logParserService.parseFile(file);
		LogAnalyserService logAnalyserService = new LogAnalyserServiceSimpleImpl();

		Map<String,Long> resultMap = logAnalyserService.getMaxExecutionTimeByType(parserResult);
		System.out.println("Maximum Time By Types:");
		for (String type : new TreeSet<String>(resultMap.keySet())) {
			System.out.println(type);
			System.out.println(resultMap.get(type));
		}

		resultMap = logAnalyserService.getMinExecutionTimeByType(parserResult);
		System.out.println("\nMinimum Time By Types:");
		for (String type : new TreeSet<String>(resultMap.keySet())) {
			System.out.println(type);
			System.out.println(resultMap.get(type));
		}

		resultMap = logAnalyserService.getAvgExecutionTimeByType(parserResult);
		System.out.println("\nAverage Time By Types:");
		for (String type : new TreeSet<String>(resultMap.keySet())) {
			System.out.println(type);
			System.out.println(resultMap.get(type));
		}
	}
}
